adding tests
authorØyvind Kolås <ok@src.gnome.org>
Sun, 14 Aug 2005 20:10:47 +0000 (20:10 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Sun, 14 Aug 2005 20:10:47 +0000 (20:10 +0000)
ChangeLog
tests/Makefile.am
tests/float_to_u8.c [new file with mode: 0644]
tests/grayscale_to_rgb.c [new file with mode: 0644]
tests/u8_to_float.c [new file with mode: 0644]

index e9ecb72da3a419817c2142d11007c27459f8965b..6eb4920605573ea20e03ff44bc4f16b7db19ec58 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-08-14  Øyvind Kolås  <pippin@gimp.org>
+       
+       * tests/float_to_u8.c
+       * tests/u8_to_float.c
+       * tests/grayscale_to_rgb.c: new files
+       * tests/Makefile.am: including preceding tests
+
 2005-08-14  Øyvind Kolås  <pippin@gimp.org>
        
        * babl/Makefile.am: added babl-instance.h, removed wilcard from
index 1ad19d8af7afc268ed987017ba0d2ee269dc87f8..081b449167b6bd4f2862138fb0279933fdc84d4a 100644 (file)
@@ -1,18 +1,25 @@
+TESTS =                                \
+       float_to_u8             \
+       grayscale_to_rgb        \
+       u8_to_float
+
+float_to_u8_SOURCES      =  float_to_u8.c
+u8_to_float_SOURCES      =  u8_to_float.c
+grayscale_to_rgb_SOURCES =  grayscale_to_rgb.c
+
+
+AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl
+LDADD = $(top_builddir)/babl/libbabl.la -lm
+
+
 noinst_PROGRAMS =      \
        introspect      \
-       nop
-AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl
+       nop             \
+       $(TESTS)
 
-introspect_SOURCES = \
-       introspect.c
-introspect_LDADD = $(top_builddir)/babl/libbabl.la
+introspect_SOURCES  =  introspect.c
+nop_SOURCES         =  nop.c
 
-nop_SOURCES = \
-       nop.c
-nop_LDADD = $(top_builddir)/babl/libbabl.la
 
-EXTRA_DIST=            \
-       .cvsignore
+EXTRA_DIST = .cvsignore
 
-TESTS=nop introspect
diff --git a/tests/float_to_u8.c b/tests/float_to_u8.c
new file mode 100644 (file)
index 0000000..5f392e2
--- /dev/null
@@ -0,0 +1,96 @@
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2005, Øyvind Kolås.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "babl.h"
+#include "babl-internal.h"
+
+#define BUFFER_LENGTH  6
+
+float float_buf[BUFFER_LENGTH]=
+{
+   0.0,  
+   1.0,
+  -1.0, 
+   2.0, 
+   0.5, 
+   0.25,
+};
+
+unsigned char u8_buf     [BUFFER_LENGTH];
+unsigned char u8_ref_buf [BUFFER_LENGTH]=
+{
+    0,
+  255,
+    0,
+  255,
+  127,
+   63,
+};
+
+int
+test_float_to_rgb_u8 (void)
+{
+  BablFish *fish;
+  int       i;
+  int      OK=1;
+
+  
+  fish = babl_fish (
+    (Babl*) babl_pixel_format_new (
+      "foo",
+      babl_model ("grayscale"),
+      babl_type ("float"),
+      babl_component ("luminance"),
+      NULL
+    ),
+    (Babl*) babl_pixel_format_new (
+      "bar",
+      babl_model ("grayscale"),
+      babl_type ("u8"),
+      babl_component ("luminance"),
+      NULL
+    ));
+
+  babl_fish_process (fish, 
+     float_buf, u8_buf, 
+     BUFFER_LENGTH);
+  
+  for (i=0; i<BUFFER_LENGTH; i++)
+    {
+      if (u8_buf[i] != u8_ref_buf[i])
+          OK=0;
+    }
+  if (!OK)
+    return -1;
+  return 0;
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+  babl_init ();
+  if (test_float_to_rgb_u8 ())
+    return -1;
+  babl_destroy ();
+  return 0;
+}
+
+
+
diff --git a/tests/grayscale_to_rgb.c b/tests/grayscale_to_rgb.c
new file mode 100644 (file)
index 0000000..7d3e717
--- /dev/null
@@ -0,0 +1,87 @@
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2005, Øyvind Kolås.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "babl.h"
+#include "babl-internal.h"
+
+#define PIXELS 5
+
+float grayscale_buf [PIXELS]= {-0.1, 0.0, 0.4, 1.0, 2.0};
+
+float rgb_buf_ref [PIXELS*3]=
+{ -0.1, -0.1, -0.1, 0.0, 0.0, 0.0, 0.4, 0.4, 0.4, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0 }; 
+
+float rgb_buf     [PIXELS*3];
+
+int
+test (void)
+{
+  BablFish *fish;
+  int       i;
+  int      OK=1;
+
+  
+  fish = babl_fish (
+    (Babl*) babl_pixel_format_new (
+      "foo",
+      babl_model ("grayscale"),
+      babl_type ("float"),
+      babl_component ("luminance"),
+      NULL
+    ),
+    (Babl*) babl_pixel_format_new (
+      "bar",
+      babl_model ("rgb"),
+      babl_type ("float"),
+      babl_component ("red"),
+      babl_component ("green"),
+      babl_component ("blue"),
+      NULL
+    ));
+
+  babl_fish_process (fish, 
+     grayscale_buf, rgb_buf, 
+     PIXELS);
+  
+  for (i=0; i<PIXELS * 3; i++)
+    {
+      if (rgb_buf[i] != rgb_buf_ref[i])
+        {
+          babl_log ("index %i is problematic", i);
+          OK=0;
+        }
+    }
+  if (!OK)
+    return -1;
+  return 0;
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+  babl_init ();
+  if (test())
+    return -1;
+  babl_destroy ();
+  return 0;
+}
+
+
+
diff --git a/tests/u8_to_float.c b/tests/u8_to_float.c
new file mode 100644 (file)
index 0000000..ca77219
--- /dev/null
@@ -0,0 +1,87 @@
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2005, Øyvind Kolås.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "babl.h"
+#include <math.h>
+#include "babl-internal.h"
+
+#define BUFFER_LENGTH  4
+#define TOLERANCE 0.003
+
+unsigned char u8_buf [BUFFER_LENGTH]= {   0,  255, 127,   63, };
+float float_ref_buf[BUFFER_LENGTH]  = { 0.0,  1.0, 0.5, 0.25, };
+float float_buf [BUFFER_LENGTH];
+
+int
+test (void)
+{
+  BablFish *fish;
+  int       i;
+  int      OK=1;
+
+  
+  fish = babl_fish (
+    (Babl*) babl_pixel_format_new (
+      "foo",
+      babl_model ("grayscale"),
+      babl_type ("u8"),
+      babl_component ("luminance"),
+      NULL
+    ),
+    (Babl*) babl_pixel_format_new (
+      "bar",
+      babl_model ("grayscale"),
+      babl_type ("float"),
+      babl_component ("luminance"),
+      NULL
+    ));
+
+  babl_fish_process (fish, 
+     u8_buf, float_buf, 
+     BUFFER_LENGTH);
+  
+  for (i=0; i<BUFFER_LENGTH; i++)
+    {
+      if (fabs (float_buf[i] - float_ref_buf[i]) > TOLERANCE)
+        {
+          babl_log ("%i .. %f-%f=%f",
+           u8_buf[i], float_buf[i], float_ref_buf[i],
+           fabs (float_buf[i] - float_ref_buf[i])
+           );
+          OK=0;
+        }
+    }
+  if (!OK)
+    return -1;
+  return 0;
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+  babl_init ();
+  if (test())
+    return -1;
+  babl_destroy ();
+  return 0;
+}
+
+
+